﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using StudentManagement.Entity;
using StudentManagement.BLL;

namespace StudentManagement.StudentsInfo
{
    /// <summary>
    /// AlterPwd.xaml 的交互逻辑
    /// </summary>
    public partial class AlterPwd : Window
    {
        public AlterPwd()
        {
            InitializeComponent();
        }
        LoginBussiness loginBussiness = new LoginBussiness();
        AlterStudenInfoBussiness alterStuden = new AlterStudenInfoBussiness();
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StudentInfoEntity studentInfoEntity = new StudentInfoEntity();
            string stuAccount = StuAccount.Text;
            string oldPwd = OldPwd.Password;
            string newPwd = NewPwd.Password.Trim();
            string reNewPwd = ReNewPwd.Password.Trim();
            if (!loginBussiness.CheckLogin(stuAccount, oldPwd))
            {
                MessageBox.Show("当前密码错误，请检查！");
                return;
            }
            if (newPwd == oldPwd)
            {
                MessageBox.Show("新密码与旧密码相同，请检查！");
                return;
            }
            if (string.IsNullOrEmpty(newPwd))
            {
                MessageBox.Show("新密码不能为空，请检查！");
                return;
            }
            if (newPwd != reNewPwd)
            {
                MessageBox.Show("两次密码不一样，请检查！");
                return;
            }
            studentInfoEntity.Account = stuAccount;
            studentInfoEntity.Password = newPwd;
            if (alterStuden.UpdatePwd(studentInfoEntity))
            {
                MessageBox.Show("密码修改成功！");
            }
            else
            {
                MessageBox.Show("密码修改失败！");
            }
        }

        
    }
}
